<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">房号：</label>
                                    <div class="layui-input-inline">
                                        <input name="roomNumber" class="layui-input" type="text" placeholder="请输入房号"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit layui-form-keyDownSearch="true">查询</button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                                </div>
                            </div>
                            <div class="query-rt"></div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button id="roomInfoBtnAdd" class="layui-btn icon-btn color-reseda">添加</button>
                        </div>
                        <div class="lay-btn-rt">
                            <button id="roomInfoBtnExport" class="layui-btn icon-btn color-green">导出</button>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="roomInfoTable" lay-filter="roomInfoTable"></table>
        </div>
    </div>
</div>

<style>
    form[lay-filter="roomInfoForm"] label {
        width: 80px;
    }

    form[lay-filter="roomInfoForm"] .layui-form-item .layui-input-inline {
        width: calc(100% - 180px);
    }
</style>
<!-- 表格操作列 -->
<script type="text/html" id="roomInfoTableBar">
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="roomInfoForm">
    <form lay-filter="roomInfoForm" class="layui-form model-form" style="padding: 20px 20px 10px;">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <div class="layui-col-md6">
                <label class="layui-form-label">空间性质</label>
                <div class="layui-input-inline">
                    <select name="spaceCharacterId" id="spaceCharacterId" lay-filter="spaceCharacterId" lay-verify="required"></select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <a href="#/system/spaceCharacter" class="layui-btn layui-btn-xs" ew-event="closeDialog"
                       title="添加空间性质">
                        <i class="layui-icon layui-icon-addition"></i>
                    </a>
                </div>
            </div>
            <div class="layui-col-md6">
                <label class="layui-form-label">所属楼栋</label>
                <div class="layui-input-inline">
                    <select name="buildingId" id="buildingId" lay-filter="buildingId" lay-verify="required"></select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <a href="#/system/buildingInfo" class="layui-btn layui-btn-xs" ew-event="closeDialog"
                       title="添加所属楼栋">
                        <i class="layui-icon layui-icon-addition"></i>
                    </a>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-col-md6">
                <label class="layui-form-label">所属楼层</label>
                <div class="layui-input-inline">
                    <select name="floorId" id="floorId"></select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <a href="#/system/floorInfo" class="layui-btn layui-btn-xs" ew-event="closeDialog" title="添加所属楼层">
                        <i class="layui-icon layui-icon-addition"></i>
                    </a>
                </div>
            </div>
            <div class="layui-col-md6">
                <label class="layui-form-label">房号</label>
                <div class="layui-input-inline">
                    <input name="roomNumber" placeholder="请输入房号" type="text" class="layui-input" lay-verify="required"/>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-col-md6">
                <label class="layui-form-label">房间名称</label>
                <div class="layui-input-inline">
                    <input name="roomName" placeholder="请输入房间名称" type="text" class="layui-input" lay-verify="required"
                           required/>
                </div>
            </div>
            <div class="layui-col-md6">
                <label class="layui-form-label">房间面积</label>
                <div class="layui-input-inline">
                    <input name="roomArea" placeholder="请输入房间面积" type="text" class="layui-input" lay-verify="required"
                           required/>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-col-md6">
                <label class="layui-form-label">房间类型</label>
                <div class="layui-input-inline">
                    <select name="roomTypeId" id="roomTypeId" lay-filter="roomTypeId" lay-verify="required"></select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <a href="#/system/roomType" class="layui-btn layui-btn-xs" ew-event="closeDialog" title="添加房间类型">
                        <i class="layui-icon layui-icon-addition"></i>
                    </a>
                </div>
            </div>
            <div class="layui-col-md6">
                <label class="layui-form-label">房间状态</label>
                <div class="layui-input-inline">
                    <select name="roomState" id="roomState">
                        <option value="0">闲置</option>
                        <option value="1">部分闲置</option>
                        <option value="2">满员</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-col-md6">
                <label class="layui-form-label">房间图片</label>
                <div class="layui-input-inline">
                    <div id="btnUpload14" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传图片
                    </div>
                    <div id="btnUpload14_path" style="margin-left: 260px;line-height: 40px;"></div>
                    <input name="roomImg" type="hidden" class="layui-input" lay-verify=""
                           id="roomImg"/>
                </div>
            </div>
            <div class="layui-col-md6" id="enterNumberBox">
                <label class="layui-form-label">已入住人数</label>
                <div class="layui-input-inline">
                    <input name="enterNumber" placeholder="请输入已入住人数" type="text" class="layui-input" pattern="\d*"
                           oninput="this.value=this.value.replace(/\D/g,'')"/>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-inline">
                <textarea id="remark" name="remark" placeholder="请输入描述" class="layui-textarea"/>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-col-md6">
                <label class="layui-form-label">是否启用</label>
                <div class="layui-input-inline">
                    <input name="deleted" type="checkbox" lay-skin="switch" value="1" checked="false" lay-text="启用|停用"/>
                </div>
            </div>
            <div class="layui-col-md6">
                <label class="layui-form-label">序号</label>
                <div class="layui-input-inline">
                    <input name="sortNumber" placeholder="请输入序号" type="text" class="layui-input" pattern="\d*"
                           oninput="this.value=this.value.replace(/\D/g,'')"/>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right" style="padding: 10px 20px 0;">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="roomInfoFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>
<!--房型管理-->
<script type="text/html" id="roomTypeWindow">
    <!-- 正文开始 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <button id="roomTypeBtnAdd" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加
                            </button>
                            <button id="roomTypeBtnExport" class="layui-btn icon-btn"><i class="layui-icon">&#xe67d;</i>导出
                            </button>
                        </div>
                    </div>
                </div>
                <!-- 表格 -->
                <table class="layui-table" id="roomTypeTable" lay-filter="roomTypeTable"></table>
            </div>
        </div>
    </div>
</script>
<!-- 房型管理表格操作列 -->
<script type="text/html" id="roomTypeTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="roomTypeForm">
    <form lay-filter="roomTypeForm" class="layui-form model-form">
        <input name="id" type="hidden"/>

        <div class="layui-form-item">
            <label class="layui-form-label">空间性质</label>
            <div class="layui-input-block">
                <select name="spaceCharacterId" id="spaceCharacterId"></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">房间类型编码</label>
            <div class="layui-input-block">
                <input name="code" placeholder="请输入房间类型编码" type="text" class="layui-input" lay-verify="required"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">房间类型名称</label>
            <div class="layui-input-block">
                <input name="name" placeholder="请输入房间类型名称" type="text" class="layui-input" lay-verify="required"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">可住人数</label>
            <div class="layui-input-block">
                <input name="peopleNumber" placeholder="请输入可住人数" type="text" class="layui-input" lay-verify="required"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea id="remark" name="remark" placeholder="请输入描述" class="layui-textarea"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block">
                <input name="deleted" type="checkbox" lay-skin="switch" value="1" checked="false" lay-text="启用|停用"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">序号</label>
            <div class="layui-input-block">
                <input name="sortNumber" placeholder="请输入序号" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="roomTypeFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>
<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'upload'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;

        $("body").delegate(".checkImg", "click", function () {
            admin.previewImg(".checkImg")
        });

        // 渲染表格
        var insTb = table.render({
            elem: '#roomInfoTable',
            url: config.base + 'enterprise/system/admin/roomInfo/list',
            toolbar: true,
            defaultToolbar: ["filter"],
            page: true,
            limit: 5,
            limits:[5,10,20,30,40,50,60,70,80],
            cellMinWidth: 100,
            cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'roomNumber', sort: true, title: '房号'}
                , {field: 'roomName', sort: true, title: '房间名称'}
                , {field: 'buildingName', sort: true, title: '所属楼栋', fixed: 'left'}
                , {field: 'floorName', sort: true, title: '所属楼层'}
                , {field: 'spaceCharacterName', sort: true, title: '空间性质'}
                , {field: 'roomArea', sort: true, title: '房间面积'}
                , {field: 'roomTypeName', sort: true, title: '房间类型'}
                , {field: 'roomState', sort: true, title: '房间状态', templet(d) {
                        if (d.roomState == 0) {
                            return '闲置'
                        } else if (d.roomState == 1) {
                            return '部分闲置'
                        } else if (d.roomState == 2) {
                            return '满员'
                        }
                }}
                , {
                    field: 'roomImg',
                    sort: true,
                    title: '房间图片',
                    templet: d => d.roomImg ? '<img class="checkImg" src="' + d.roomImg + '"/>' : '<img src="assets/images/default-icon.png"/>'
                }
                , {field: 'enterNumber', sort: true, title: '已入住人数', width: 120}
                , {field: 'createTime', sort: true, title: '创建时间'}
                , {
                    field: 'deleted', sort: true, title: '是否启用', fixed: 'right', templet: function (d) {
                        if (d.deleted) {
                            return '<input name="deleted" type="checkbox" lay-skin="switch" value="' + d.id + '" checked="' + d.deleted + '" lay-filter="deleted"  lay-text="启用|停用"/>';
                        } else {
                            return '<input name="deleted" type="checkbox" lay-skin="switch" value="' + d.id + '" lay-filter="deleted"   lay-text="启用|停用"/>';
                        }
                    }
                }
                , {align: 'center', toolbar: '#roomInfoTableBar', title: '操作', width: 200, fixed: 'right'}
            ]],
            done: function (res, curr, count) {

            }
        });

        // 工具条点击事件
        table.on('tool(roomInfoTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                showEditModel(data);
            } else if (obj.event === 'del') { // 删除
                doDelete(obj);
            }
        });

        //监听排序
        table.on('sort(roomInfoTable)', function (obj) {
            table.reload('roomInfoTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field,page: {curr: 1}},'data');
        });

        // 重置搜索
        form.on('submit(resets)', data => {
            insTb.reload({where: admin.resetSearch(data.field), page: {curr: 1}}, 'data');
        });

        // 添加按钮点击事件
        $('#roomInfoBtnAdd').click(function () {
            showEditModel();
        });
        form.on('switch(deleted)', function (obj) {
            if (obj.elem.checked) {
                enable(obj.value)
            } else {
                disable(obj.value)
            }
        })

        function enable(id) {
            admin.req('enterprise/system/admin/roomInfo/enable', {id: id}, function (res) {
                if (res.code == 200) {
                    layer.msg(res.msg, {icon: 1});
                    insTb.reload('systemWorkmanshipTable');
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'POST');
        }

        function disable(id) {
            admin.req('enterprise/system/admin/roomInfo/disable', {id: id}, function (res) {
                if (res.code == 200) {
                    layer.msg(res.msg, {icon: 1});
                    insTb.reload('systemWorkmanshipTable');
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'POST');
        }

        // 显示编辑弹窗
        function showEditModel(data) {
            admin.open({
                type: 1,
                area: '820px',
                offset: '65px',
                title: data ? '修改房号管理' : '添加房号管理',
                content: $('#roomInfoForm').html(),
                success: function () {
                    if (data) {
                        getFloorData(data.buildingId);
                        getRoomTypeData(data.spaceCharacterId);
                        isShowEnterNumber(data.roomTypeName);
                    }
                    if (data && data.roomImg) {
                        $('#btnUpload14_path').html('<img src="' + data.roomImg + '" style="height: 50px;" />');
                    }
                    //查询企业信息
                    var enterpriseInfo;
                    admin.req('enterprise/system/admin/enterpricceId/getEnterpricceIdVO', {}, function (res) {
                        enterpriseInfo = res.data;
                    }, 'get', false);
                    if ("" == enterpriseInfo || null == enterpriseInfo) {
                        layer.msg("企业信息获取异常", {icon: 1});
                        return;
                    }
                    //var productCode = $("input[name='productCode']").val();

                    upload.render({
                        elem: '#btnUpload14'
                        , url: config.upload_url + 'uploadFile'
                        , data: {"path": enterpriseInfo.enterpriseCode + "/"}
                        , accept: 'file'
                        , exts: 'jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx'
                        , headers: {Authorization: 'Bearer ' + config.getToken()}
                        , done: function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                var imagUrl = res.data.url;
                                // if(imagUrl){
                                //     imagUrl=imagUrl.substring(imagUrl.indexOf('/')+1)
                                // }
                                $('#btnUpload14_path').html('<img src="' + imagUrl + '" style="height: 50px;" />');
                                $('#roomImg').val(imagUrl);
                            } else if (res.code == 502) {
                                return location.replace('admin/login.html');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    });

                    // 请求所属楼栋
                    admin.reqSync('enterprise/system/admin/buildingInfo/list', {limit: 9999}, function (res) {
                        if (res.code == 200) {
                            loadReportSelectHtml(res.data, '', 'buildingId', 1, 'roomInfoForm');
                            if (!data && res.data.length > 0){
                                getFloorData(res.data[0].id);
                            }
                        } else {
                            loadReportSelectHtml([], '', 'buildingId', 1, 'roomInfoForm');
                        }
                    }, 'GET');

                    // 所属楼栋下拉事件
                    form.on('select(buildingId)', function (data) {
                        getFloorData(data.value)
                    });

                    //请求所属楼层
                    function getFloorData(_id) {
                        if (_id) {
                            admin.reqSync('enterprise/system/admin/floorInfo/list', {
                                limit: 9999,
                                buildingId: _id
                            }, function (res) {
                                if (res.code == 200) {
                                    loadReportSelectHtml(res.data, '', 'floorId', 1, 'roomInfoForm');
                                } else {
                                    loadReportSelectHtml([], '', 'floorId', 1, 'roomInfoForm');
                                }
                            }, 'GET');
                        } else {
                            loadReportSelectHtml([], '', 'floorId', 1, 'roomInfoForm');
                        }
                    }

                    // 请求空间性质
                    admin.reqSync('enterprise/system/admin/spaceCharacter/list', {limit: 9999}, function (res) {
                        if (res.code == 200) {
                            loadReportSelectHtml(res.data, '', 'spaceCharacterId', 1, 'roomInfoForm');
                            if (!data && res.data.length > 0){
                                getRoomTypeData(res.data[0].id);
                            }
                        } else {
                            loadReportSelectHtml([], '', 'spaceCharacterId', 1, 'roomInfoForm');
                        }
                    }, 'GET');

                    // 空间性质下拉事件
                    form.on('select(spaceCharacterId)', function (data) {
                        getRoomTypeData(data.value);
                    });

                    // 请求房间类型数据
                    function getRoomTypeData(_id){
                        if (_id) {
                            admin.reqSync('enterprise/system/admin/roomType/list', {
                                limit: 9999,
                                spaceCharacterId: _id
                            }, function (res) {
                                if (res.code == 200) {
                                    loadReportSelectHtml(res.data, '', 'roomTypeId', 1, 'roomInfoForm');
                                    if (!data && res.data.length > 0){
                                        isShowEnterNumber(res.data[0].name);
                                    }
                                } else {
                                    loadReportSelectHtml([], '', 'roomTypeId', 1, 'roomInfoForm');
                                }
                            }, 'GET');
                        } else {
                            loadReportSelectHtml([], '', 'roomTypeId', 1, 'roomInfoForm');
                        }
                    }

                    //房间类型下拉事件
                    form.on('select(roomTypeId)', function (data) {
                        isShowEnterNumber(data.elem[data.elem.selectedIndex].text);
                    });

                    function isShowEnterNumber(_text){
                        if (_text.indexOf('宿舍')!=-1){
                            $('#enterNumberBox').show();
                        }else {
                            $('#enterNumberBox').hide();
                            $('#enterNumberBox').find('input').val('')
                        }
                    }

                    form.val('roomInfoForm', data);
                    // 表单提交事件
                    form.on('submit(roomInfoFormSubmit)', function (d) {
                        if (d.field.spaceCharacterId == '') {
                            layer.msg('请选择空间性质', {icon: 2});
                            return false;
                        }
                        if (d.field.buildingId == '') {
                            layer.msg('请选择所属楼栋', {icon: 2});
                            return false;
                        }
                        if (d.field.roomTypeId == '') {
                            layer.msg('请选择房间类型', {icon: 2});
                            return false;
                        }
                        layer.load(2);
                        if(!d.field.enterNumber){
                            d.field.enterNumber = 0;
                        }
                        admin.req(data ? 'enterprise/system/admin/roomInfo/update' : 'enterprise/system/admin/roomInfo/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('roomInfoTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST');
                        return false;
                    });
                }
            });
        }

        //房型管理
        $('#roomTypeBtn').click(function () {
            admin.open({
                type: 1,
                area: '1000px',
                offset: '65px',
                title: '房型管理',
                content: $('#roomTypeWindow').html(),
                success: function () {
                    // 渲染表格
                    var insTb = table.render({
                        elem: '#roomTypeTable',
                        url: config.base + 'enterprise/system/admin/roomType/list',
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            , {field: 'sortNumber', sort: true, title: '序号'}
                            , {field: 'code', sort: true, title: '房间类型编码'}
                            , {field: 'name', sort: true, title: '房间类型名称'}
                            , {field: 'peopleNumber', sort: true, title: '可以驻人数'}
                            , {field: 'spaceCharacterName', sort: true, title: '空间性质'}
                            , {
                                field: 'deleted', sort: true, title: '是否启用', templet: function (d) {
                                    if (d.deleted) {
                                        return '<input name="deleted" type="checkbox" lay-skin="switch" value="' + d.id + '" checked="' + d.deleted + '" lay-filter="deleted"  lay-text="启用|停用"/>';
                                    } else {
                                        return '<input name="deleted" type="checkbox" lay-skin="switch" value="' + d.id + '" lay-filter="deleted"   lay-text="启用|停用"/>';
                                    }
                                }
                            }
                            , {field: 'createTime', sort: true, title: '创建时间'}
                            , {align: 'center', toolbar: '#roomTypeTableBar', title: '操作', width: 200}
                        ]],
                        done: function (res, curr, count) {

                        }
                    });

                    // 工具条点击事件
                    table.on('tool(roomTypeTable)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'edit') { //修改
                            showRoomTypeEditModel(data);
                        } else if (obj.event === 'del') { // 删除
                            doDelete(obj);
                        }
                    });

                    // 添加按钮点击事件
                    $('#roomTypeBtnAdd').click(function () {
                        showRoomTypeEditModel();
                    });

                    form.on('switch(deleted)', function (obj) {
                        if (obj.elem.checked) {
                            roomTypeEnable(obj.value)
                        } else {
                            roomTypeDisable(obj.value)
                        }
                    })

                    function roomTypeEnable(id) {
                        admin.req('enterprise/system/admin/roomType/enable', {id: id}, function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                insTb.reload('systemWorkmanshipTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST');
                    }

                    function roomTypeDisable(id) {
                        admin.req('enterprise/system/admin/roomType/disable', {id: id}, function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                insTb.reload('systemWorkmanshipTable');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST');
                    }

                    // 显示编辑弹窗
                    function showRoomTypeEditModel(data) {

                        admin.req('enterprise/system/admin/spaceCharacter/list', {limit: 9999}, function (res) {
                            if (res.code == 200) {
                                if (res.data.length > 0) {
                                    $.each(res.data, function (index, item) {
                                        $("#spaceCharacterId").append(new Option(item.name, item.id));
                                    })
                                    form.render('select');
                                }
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                        admin.open({
                            type: 1,
                            area: '700px',
                            offset: '65px',

                            title: data ? '修改房间类型' : '添加房间类型',
                            content: $('#roomTypeForm').html(),
                            success: function () {
                                form.val('roomTypeForm', data);
                                // 表单提交事件
                                form.on('submit(roomTypeFormSubmit)', function (d) {
                                    layer.load(2);
                                    admin.req(data ? 'enterprise/system/admin/roomType/update' : 'enterprise/system/admin/roomType/add', d.field, function (res) {
                                        layer.closeAll('loading');
                                        if (res.code == 200) {
                                            layer.msg(res.msg, {icon: 1});
                                            table.reload('roomTypeTable');
                                            layer.closeAll('page');
                                        } else {
                                            layer.msg(res.msg, {icon: 2});
                                        }
                                    }, data ? 'PUT' : 'POST');
                                    return false;
                                });
                            }
                        });
                    }

                    // 删除
                    function doDelete(obj) {
                        layer.confirm('确定要删除吗？', {
                            offset: '65px',
                            skin: 'layui-layer-admin'
                        }, function (i) {
                            layer.close(i);
                            layer.load(2);
                            admin.req('enterprise/system/admin/roomType/' + obj.data.id, {}, function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    obj.del();
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'DELETE');
                        });
                    }
                }
            })
        });

        // 删除
        function doDelete(obj) {
            layer.confirm('确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprise/system/admin/roomInfo/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        // 导出excel
        $('#roomInfoBtnExport').click(function () {
            var checkRows = table.checkStatus('roomInfoTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });

        // 渲染下拉框
        function loadReportSelectHtml(data, tips, htmltarget, type, parentForm) {
            let html = '';
            if (tips) {
                html = ' <option value="">' + tips + '</option>';
            }
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                if (type == 1) {
                    html += `<option value='${data[i].id}'>${data[i].name}</option>`;
                } else if (type == 2) {
                    html += `<option value='${data[i].cabCode}'>${data[i].cabCode}</option>`;
                }
            }
            $("form[lay-filter='" + parentForm + "']").find("select[name='" + htmltarget + "']").html(html);
            form.render('select');
        }

    });
</script>